<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .lamp  {
      width: 150px;
      height: 150px;
      margin: 100px auto;
      border-radius: 50%;
      background-color: orange;
    }
  </style>
</head>
<body>
  <div class="lamp"></div>
</body>
<script>
  function sleep(duration) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve()
      }, duration);
    })
  }
  async function changeColor(duration, color) {
    document.querySelector('.lamp').style.background = color;
    await sleep(duration)
  }
  async function  main() {
    while(true) {
      await changeColor(3000, 'green')
      await changeColor(2000, 'yellow')
      await changeColor(1000, 'red')
    }
  }
  main()
</script>
</html>